﻿<Controls:MetroWindow x:Class="AzureVMDashboard.UI.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ui="clr-namespace:AzureVMDashboard.UI"
        xmlns:model="clr-namespace:AzureVMDashboard.Model"
        xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        DataContext="{Binding Source={StaticResource Locator}, Path=Main}"
        ShowIconOnTitleBar="True"
        Icon="/Resources/mainIcon.ico"
        ShowInTaskbar="True"
        ShowTitleBar="True"
        Title="Dashboard-AzureVM" Height="350" Width="750">
    <Controls:MetroWindow.Resources>
        <ui:InfoMessageToVisibilityConverter x:Key="InfoMessageToVisibility" />
        <ui:ExistToVisibilityConverter x:Key="ExistToVisibility" />
        <BooleanToVisibilityConverter x:Key="BoolToVisibility" />
    </Controls:MetroWindow.Resources>
    <Controls:MetroWindow.WindowCommands>
        <Controls:WindowCommands>
            <Button Command="{Binding CmdSettings}" IsEnabled="{Binding Source={x:Static ui:App.Resources}, Path=VMController.IsIdle}">
                <StackPanel Orientation="Horizontal">
                    <Rectangle Width="15" Height="15">
                        <Rectangle.Resources>
                            <SolidColorBrush x:Key="BlackBrush" Color="White" />
                        </Rectangle.Resources>
                        <Rectangle.Fill>
                            <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_settings}" />
                        </Rectangle.Fill>
                    </Rectangle>
                   <!--  <TextBlock Margin="5,0,0,0" Text="settings" /> -->
                </StackPanel>
            </Button>
            <Button Command="{Binding CmdAbout}">
                <StackPanel Orientation="Horizontal">
                    <Rectangle Width="10" Height="10">
                        <Rectangle.Resources>
                            <SolidColorBrush x:Key="BlackBrush" Color="White" />
                        </Rectangle.Resources>
                        <Rectangle.Fill>
                            <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_question}" />
                        </Rectangle.Fill>
                    </Rectangle>
                    <!--  <TextBlock Margin="5,0,0,0" Text="settings" /> -->
                </StackPanel>
            </Button>
        </Controls:WindowCommands>
    </Controls:MetroWindow.WindowCommands>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <Border BorderThickness="0,0,0,2" BorderBrush="Gainsboro">
            <DockPanel Grid.Row="0">
                <ComboBox ItemsSource="{Binding Source={x:Static ui:App.Resources}, Path=VMController.AzureSubscriptions}"
                          IsEnabled="{Binding Source={x:Static ui:App.Resources}, Path=VMController.IsIdle}"
                          SelectedItem="{Binding Source={x:Static ui:App.Resources}, Path=CurrentSubscription, Mode=TwoWay}"
                          SelectionChanged="ComboBox_SelectionChanged_1"
                          Width="271"  Height="35" Margin="0,2"/>
                <Button Margin="5,0,0,0" Content="Refresh" Command="{Binding CmdRefresh}" Height="35" Width="80" IsEnabled="{Binding Source={x:Static ui:App.Resources}, Path=VMController.IsIdle}"></Button>
                <Button Margin="5,0,0,0" Content="Start All" Command="{Binding CmdStart}" Height="35" Width="80" IsEnabled="{Binding Source={x:Static ui:App.Resources}, Path=VMController.IsIdle}"></Button>
                <Button Margin="5,0,0,0" Content="Stop All" Command="{Binding CmdStop}" Height="35" Width="80" IsEnabled="{Binding Source={x:Static ui:App.Resources}, Path=VMController.IsIdle}"></Button>
                <TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0">
                       <Hyperlink RequestNavigate="HandleRequestNavigate" x:Name="hl1" NavigateUri="https://manage.windowsazure.com">
                             Azure Portal
                       </Hyperlink>
                </TextBlock>
            </DockPanel>
        </Border>

        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="300"/>
                </Grid.ColumnDefinitions>
            <ListView Grid.Column="0" BorderThickness="0" x:Name="vmList" ItemsSource="{Binding Source={x:Static ui:App.Resources}, Path=CurrentSubscription.VMs}" IsEnabled="{Binding Source={x:Static ui:App.Resources}, Path=VMController.IsIdle}">
                <ListView.ItemTemplate>
                    <DataTemplate >
                        <ui:VMControl VM="{Binding}"  />
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            
            <ui:VMDetailControl Opacity="0.8" Grid.Column="1" MinWidth="200" VM="{Binding ElementName=vmList, Path=SelectedItem, Mode=OneWay}" Visibility="{Binding ElementName=vmList, Path=SelectedItem, Mode=OneWay, Converter={StaticResource ExistToVisibility}}"></ui:VMDetailControl>
            <GridSplitter ResizeDirection="Columns" Grid.Column="1" HorizontalAlignment="Left" Background="Gainsboro" Grid.Row="0" Width="2"  Height="Auto" VerticalAlignment="Stretch" Margin="0" Visibility="{Binding ElementName=vmList, Path=SelectedItem, Mode=OneWay, Converter={StaticResource ExistToVisibility}}" />
        </Grid>
       
        <StatusBar Grid.Row="2">            
            <StatusBarItem>
                <StackPanel Orientation="Horizontal">
                    <Button Margin="0"  VerticalAlignment="Center"  Height="20" Command="{Binding CmdOpenLog}" FontSize="10" Padding="7,0,7,0">Log</Button>
                    <Separator />
                    <Rectangle Fill="Red" Opacity="0.7" Width="4" Margin="5,0,5,0" Height="13" Visibility="{Binding StatusMessage, Converter={StaticResource InfoMessageToVisibility}}">
                        <Rectangle.OpacityMask>
                            <VisualBrush Visual="{StaticResource appbar_exclamation}" Stretch="Fill" />
                        </Rectangle.OpacityMask>
                    </Rectangle>
                    <TextBlock VerticalAlignment="Center" Margin="2,0,0,0" FontSize ="10" Text="{Binding StatusMessage.Message}" />
                </StackPanel>
            </StatusBarItem>
            <StatusBarItem HorizontalAlignment="Right">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Margin="0,0,10,0" FontSize ="10" VerticalAlignment="Center" Visibility="{Binding Source={x:Static ui:App.Resources}, Path=VMController.IsWorking, Converter={StaticResource BoolToVisibility}}">Working</TextBlock>
                    <TextBlock Margin="0,0,10,0" FontSize ="10" VerticalAlignment="Center" Visibility="{Binding Source={x:Static ui:App.Resources}, Path=VMController.IsIdle, Converter={StaticResource BoolToVisibility}}">Ready</TextBlock>
                    <ProgressBar Grid.Column="1"  Foreground="{StaticResource BlueAzure}" HorizontalAlignment="Right" Width="60" Height="20" VerticalAlignment="Center" Visibility="{Binding Source={x:Static ui:App.Resources}, Path=VMController.IsWorking, Converter={StaticResource BoolToVisibility}}" IsIndeterminate="True"/>
                </StackPanel>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Controls:MetroWindow>
